home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 July: Mac OS SDK / Dev.CD Jul 97 SDK1.toast / Development Kits (Disc 1) / QuickDraw GX / Programming Stuff / GX Libraries / RampLibrary.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-03-31  |  2.3 KB  |  71 lines  |  [TEXT/MPS ]

  1.  
  2. /*
  3.     File:        RampLibrary.c
  4.  
  5.     Contains:    ramp library - gxShape library
  6.     
  7.     Written by:    Cary Clark, Georgiann Delaney, Michael Fairman, Dave Good, Robert Johnson, Keith McGreggor, Oliver Steele, David Van Brink, Chris Yerga
  8.     
  9.     Copyright:    © 1995 by Apple Computer, Inc., all rights reserved.
  10.  
  11.     Change History (most recent first):
  12.  
  13.          <1>      1/9/95    JD        First checked in.
  14. */
  15.  
  16. #include "GraphicsLibraries.h"
  17.  
  18. static gxBitmap rampBits = {nil, 1, 0, 0, 32, gxNoSpace, nil, nil};
  19.  
  20. gxShape NewRamp(register const gxColor *start, register const gxColor *end, register long count, const gxRectangle *bounds)
  21. {
  22.     if (count == 0)
  23.         count = 256;
  24.     rampBits.height = count--;
  25.     {   register gxShape rampShape = GXNewBitmap(&rampBits, nil);
  26.         register long d1 = ((long) end->element.component[0] - (long) start->element.component[0]) / count;
  27.         register long d2 = ((long) end->element.component[1] - (long) start->element.component[1]) / count;
  28.         register long d3 = ((long) end->element.component[2] - (long) start->element.component[2]) / count;
  29.         register long d4 = ((long) end->element.component[3] - (long) start->element.component[3]) / count;
  30.         gxColor accum;
  31.     
  32.         accum = *end;
  33.         do {
  34.             GXSetShapePixel(rampShape, 0, count, &accum, 0);
  35.             accum.element.component[0] -= d1;   
  36.             accum.element.component[1] -= d2;   
  37.             accum.element.component[2] -= d3;   
  38.             accum.element.component[3] -= d4;
  39.         } while (--count >= 0);
  40.         if (bounds)
  41.             GXSetShapeBounds(rampShape, bounds);
  42.         return rampShape;
  43.     }
  44. }
  45.  
  46.  
  47. void DrawRamp(const gxColor *start, const gxColor *end, long count, const gxRectangle *bounds)
  48. {
  49.     register gxShape ramp = NewRamp(start, end, count, bounds);
  50.     
  51.     GXDrawShape(ramp);
  52.     GXDisposeShape(ramp);
  53. }
  54.  
  55.  
  56. gxShape NewCommonRamp(commonColor start, commonColor end, long count, const gxRectangle *bounds)
  57. {
  58.     gxColor startColor, endColor;
  59.     
  60.     return NewRamp(SetCommonColor(&startColor, start), SetCommonColor(&endColor, end), count, bounds);
  61. }
  62.  
  63.  
  64. void DrawCommonRamp(commonColor start, commonColor end, long count, const gxRectangle *bounds)
  65. {
  66.     register gxShape ramp = NewCommonRamp(start, end, count, bounds);
  67.     
  68.     GXDrawShape(ramp);
  69.     GXDisposeShape(ramp);
  70. }
  71.